<?php
/***
	PDMS元件型码的管理，包括：
	1. 查询；

***/
class Pdms_shapcode extends CI_Controller {
	
	public function __construct() {
		parent::__construct();
		$this->load->model('pdms_type_model');
		$this->load->model('pdms_shapcode_model');
		$this->load->model('pdms_standard_model');
		$this->load->model('pdms_subtype_model');
		$this->load->model('pdms_contype_model');
		$this->load->model('pdms_classthk_model');
		$this->load->model('pdms_size_model');
		$this->load->helper('url');
	}
	
	/***
	查询。
	***/
	public function index( ) {
		
		//如果POST form1表示查询表单传来数据
		//根据传来代码去查询
		$flag_list = 0;
		if (isset($_POST['form1'])) {
			$data['shaps'] = $this->pdms_shapcode_model->get_by_code();
			$flag_list = 1;
			
			$type = $this->input->post('type');
			$standard = $this->input->post('standard');
			$subtype = $this->input->post('subtype');
			$contype = $this->input->post('contype');
			$classthk = $this->input->post('classthk');
			$dn1 = $this->input->post('dn1');
			$dn2 = $this->input->post('dn2');
		
			$data['code'] = $standard.$type.$subtype.$contype.$classthk.$dn1.$dn2;
			
			
		}
		//类别、连接方式、壁厚等级、尺寸是预先加载
		//标准和子类别是异步加载
		//这里只做预先加载内容
		$data['types'] = $this->pdms_type_model->get_all( );
		$data['contypes'] = $this->pdms_contype_model->get_all( );
		$data['classthks'] = $this->pdms_classthk_model->get_all( );
		$data['sizes'] = $this->pdms_size_model->get_all( );
		
		$data['title'] = "元件型码查询";
		
		$this->load->library('parser');
		
		$this->load->view('templates/pdms_head');
		$this->load->view('templates/pdms_menu');
		$this->parser->parse('pdms_shapcode/form', $data);
		if ($flag_list == 1) {
			//输出列表
			$this->parser->parse('pdms_shapcode/list', $data);
		}
		$this->load->view('templates/foot');
		
	}
	
	public function get_standard( ) {
		$type_code = $_POST['type_code'];
		
		$standards = $this->pdms_standard_model->get_by_type($type_code);
		$back_string = "<option value='__'>请选择</option>";
		foreach ($standards as $standard) {
			$back_string = $back_string."<option value = '".$standard['code']."'>".$standard['des']."</option>";
		}
		echo $back_string;
	}
	
	public function get_subtype( ) {
		$type_code = $_POST['type_code'];
		
		$subtypes = $this->pdms_subtype_model->get_by_type($type_code);
		$back_string = "<option value='_'>请选择</option>";
		foreach ($subtypes as $subtype) {
			$back_string = $back_string."<option value = '".$subtype['code']."'>".$subtype['des']."</option>";
		}
		echo $back_string;
	}
}